<template>
  <div class="reply-box">

    <el-form ref="replyForm"
             :model="form"
             label-width="0px"
             :rules="rules">
      <el-form-item prop="content">
        <el-input type="textarea"
                  ref="replyBody"
                  :rows="4"
                  placeholder="支持部分markdown语法，请勿发布敏感、负能量、不友善等内容..."
                  v-model="form.content">
        </el-input>
      </el-form-item>
    </el-form>
    <div class="submit-btn">
      <el-button type="primary"
                 size="small"
                 :loading="loading"
                 @click="reply">发布</el-button>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    submit: {
      type: Function,
      required: true
    },
    replyPerson: {
      type: Object,
      default: () => { }
    }
  },
  data () {
    return {
      form: {
        content: ''
      },
      loading: false,
      rules: {
        content: [
          { required: true, message: '内容不能为空' }
        ]
      }
    }
  },
  methods: {
    async reply () {
      await this.$refs.replyForm.validate()
      this.loading = true
      await this.submit({ ...this.form })
      this.loading = false
      await this.$refs.replyForm.resetFields()
    }
  }
}
</script>

<style lang="scss" scoped>
.reply-box {
  display: flex;
  flex-direction: column;
  .submit-btn {
    margin: 10px 0 20px 0;
    display: flex;
    flex-direction: row-reverse;
  }
}
</style>